package fox.framework.rpc.context;

import fox.framework.rpc.client.RpcClient;
import fox.framework.rpc.client.invocation.ConsumeInvoker;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Rpc代理支持类
 *
 * @author cuichao
 * @Description: RpcProxySupport
 * @Date: create in 2021/3/5 14:34
 */
public final class RpcProxySupport {

    private static RpcClient client;
    private final static List<ConsumeInvoker> invokers = new ArrayList<>();

    /**
     * 初始化RpcClient
     *
     * @param client
     */
    static void initRuntimeRpcClient(RpcClient client) {
        RpcProxySupport.client = client;
    }
    /**
     * 初始化消费者代理执行器
     *
     * @param invokers
     */
    static void initRegisteredProxyInvoker(List<ConsumeInvoker> invokers) {
        RpcProxySupport.invokers.clear();
        RpcProxySupport.invokers.addAll(invokers);
    }

    public static RpcClient getRunTimeRpcClient() {
        if (client == null) {
            String msg = "the Rpc-Client is null , please call this method at running time";
            throw new IllegalArgumentException(msg);
        }
        return RpcProxySupport.client;
    }


    public static List<ConsumeInvoker> getRegisteredProxyInvoker() {
        return Collections.unmodifiableList(RpcProxySupport.invokers);
    }



}
